package org.jeecg.modules.demo.mpwlwjc.service.impl;

import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.demo.mpwlwjc.entity.ZwglEventControl;
import org.jeecg.modules.demo.mpwlwjc.mapper.ZwglEventControlMapper;
import org.jeecg.modules.demo.mpwlwjc.service.IZwglEventControlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Description: 报警处理
 * @Author: jeecg-boot
 * @Date: 2023-04-13
 * @Version: V1.0
 */
@Service
public class ZwglEventControlServiceImpl extends ServiceImpl<ZwglEventControlMapper, ZwglEventControl> implements IZwglEventControlService {


    @Autowired
    private ZwglEventControlMapper zwglEventControlMapper;

    @Override
    @Transactional
    public Result<?> handleDealWithData(String id, String index) {
        ZwglEventControl zwglEventControl = zwglEventControlMapper.selectById(id);
        if (oConvertUtils.isEmpty(zwglEventControl) || oConvertUtils.isEmpty(zwglEventControl.getId())) {
            return Result.error("数据不合法");
        }
        if (!zwglEventControl.getEventStatus().equals("0")) {
            return Result.error("报警已处理，无需重复处理");
        }
        zwglEventControl.setEventStatus(index);
        if (zwglEventControlMapper.updateById(zwglEventControl) <= 0) {
            throw new JeecgBootException("数据处理异常，稍后重试");
        }
        return Result.OK();
    }
}
